<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE HTML>
<html>
<head>
<jsp:include page="common_header.jsp" flush="true"></jsp:include>
<title>新建网站角色 - 管理员管理 - H-ui.admin v3.1</title>
</head>
<body>
<article class="page-container">
	<form action="" method="post" class="form form-horizontal" id="form-admin-role-add">
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>查询字段：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="" placeholder="" id="" name="queryCode">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>字典项代码：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="" placeholder="" id="" name="itemCode">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>字典项名称：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="" placeholder="" id="" name="itemName">
			</div>
		</div>
		<div class="row cl">
			<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
				<button type="submit" class="btn btn-success radius" id="admin-role-save" name="admin-role-save"><i class="icon-ok"></i> 确定</button>
			</div>
		</div>
	</form>
</article>

<jsp:include page="_footer.jsp" flush="true"></jsp:include>
<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript">
var dictId;
$(function(){
	$("#form-admin-role-add").validate({
		rules:{
			queryCode:{
				required:true,
				minlength:2,
				maxlength:30
			},
			itemCode:{
				required:true,
				maxlength:30
			},
			itemName:{
				required:true,
				maxlength:50
			}
		},
		onkeyup:false,
		focusCleanup:true,
		success:"valid",
		submitHandler:function(form){
// 			$(form).ajaxSubmit();
// 			var index = parent.layer.getFrameIndex(window.name);
// 			parent.layer.close(index);
			addOrUpdateDict();
		}
	});
});


function addOrUpdateDict(){
	var url = "${path}/sysDict/add.do";
	var type = '添加';
	var formData = $('#form-admin-role-add').serialize();
	if (dictId) {
		url = "${path}/sysDict/update.do";
		type = '修改';
		formData += '&id='+dictId;
	}
	$.ajax({
		url: url,
		data: formData, 
		type: "POST",
		success: function(data, textStatus){
			if (data.code == 0) {
				layer.msg(type+'成功!',{icon:1,time:1000});
				setTimeout(function(){
					var index = parent.layer.getFrameIndex(window.name);
					parent.refresh(index);
				}, 1500);
			}else{
				alert(type+"失败！");
			}
		},
		error: function (data, textStatus, errorThrown) {
			alert("系统错误！");
		}
	});	
	
}

function fillData(id){
	dictId = id;
	$.ajax({
		url: "${path}/sysDict/detail.do",
		data: 'id='+id, 
		type: "POST",
		success: function(data, textStatus){
			if (data.code == 0) {
				var obj = data.data;
				fillFormByName('form-admin-role-add', obj);
			}else{
				alert(data.msg);
			}
		},
		error: function (data, textStatus, errorThrown) {
			var s=JSON.stringify(data);
		}
	});
}

</script>
</body>
</html>
